﻿//树状栏左右移动
var dragenable = false;
var a_x = 0;
var a_y = 0;
var a_leftWidth = 0;
var a_leftNewWidth = 0;
var a_Height = 0;
var a_NewHeight = 0;
var a_maxY = 0;
var a_minY = 0;
var objMove = null; // document.getElementById("splitBar");
function a_init(event) {
    objMove = window.event ? window.event.srcElement : event.target;
    a_x = event.clientX;
    a_y = event.clientY;
    if (objMove.id == 'splitBar') {
        a_leftWidth = $('#td_left').width();
        if (!$("#leftopen").is(":hidden")) {
            showleft();
        }
    }
    else if (objMove.id == 'HorizontalSplitBar') {
        var _td_main = $('#td_main');
        a_maxY = _td_main.offset().left + _td_main.height() - 10;
        a_minY = _td_main.offset().left;
        a_Height = $('#statewin_tool').height();
    }

    // if (document.all) {
    try {
        objMove.setCapture();
    } catch (e) { }
    // }

    dragenable = true;
    //objMove.style.cursor = 'e-resize';
}
if (!document.all) {
    document.onmouseup = function (event) {
        dragenable = false;
    };

    document.onmouseover = function (event) {
        var obj = window.event ? window.event.srcElement : event.target;
        if (obj.id != undefined) {
            if (obj.id == 'splitBar') {

            }
            else {
                if (dragenable) {
                    if (objMove.id == 'splitBar') {
                        var tool_left = $('#td_left');
                        var splitwidth = $('#splitBar').width();
                        if (event.clientX < 101) {

                            tool_left.width(100 - splitwidth);
                            setWinHeightAndWidth();
                        }
                        else if (event.clientX > 601) {
                            tool_left.width(600 - splitwidth);
                            setWinHeightAndWidth();
                        }
                        else {
                            a_leftNewWidth = a_leftWidth + (event.clientX - a_x);
                            tool_left.width(a_leftNewWidth);
                            setWinHeightAndWidth();
                        }
                        //记录left宽度
                        cookie.setCookie('leftwh', tool_left.width());
                    }
                    else if (objMove.id == 'HorizontalSplitBar') {

                    }
                }

                a_end(event);
            }
        } else {
            a_end(event);
        }
    }
}
function a_drag(event) {
    var tool_left = $('#td_left');
    if (dragenable) {
        if (objMove.id == 'splitBar') {
            var splitwidth = $('#splitBar').width();
            if (event.clientX < 101) {

                tool_left.width(100 - splitwidth);
                setWinHeightAndWidth();
            }
            else if (event.clientX > 601) {
                tool_left.width(600 - splitwidth);
                setWinHeightAndWidth();
            }
            else {
                a_leftNewWidth = a_leftWidth + (event.clientX - a_x);
                tool_left.width(a_leftNewWidth);
                setWinHeightAndWidth();
            }
            //记录left宽度
            cookie.setCookie('leftwh', tool_left.width());
        }
        else if (objMove.id == 'HorizontalSplitBar') {
            var _mainwin_tool = $('#mainwin_tool');
            var _mainwin = $('#mainwin');
            var _statewin_tool = $('#statewin_tool');
            var _statewin = $('#statewin');
            a_NewHeight = a_Height - (event.clientY - a_y);
            //document.title = a_NewHeight; //测试用
            var m_t_h = _mainwin_tool.height();
            // alert(event.clientY - a_y);
            if (_mainwin_tool.position().top + 100 > event.clientY) { return; }
            if (event.clientY > document.body.clientHeight - 10) { return; }
            _mainwin_tool.height(m_t_h + event.clientY - a_y);
            _mainwin.height(m_t_h + event.clientY - a_y);
            _statewin_tool.height(a_NewHeight);
            _statewin.height(a_NewHeight - 10);
            setMainToolWidthAndHeight();
        }
    }
}
function a_end(event) {
    dragenable = false;
    if (document.all) {
        objMove = window.event ? window.event.srcElement : event.target;
        objMove.releaseCapture();
    }
}
$(document).ready(function () {
    $('#splitBar').mousedown(function (event) { a_init(event); return false; });
    $('#splitBar').mousemove(function (event) { a_drag(event); return false; });
    $('#splitBar').mouseup(function (event) { a_end(event); return false; });
    $('#HorizontalSplitBar').mousedown(function (event) { a_init(event); return false; });
    $('#HorizontalSplitBar').mousemove(function (event) { a_drag(event); return false; });
    $('#HorizontalSplitBar').mouseup(function (event) { a_end(event); return false; });
});